package com.tangruojie.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
@Component
@ConfigurationProperties(prefix = "myapp")
public class MyAppProperties {

    // 基础字段类型
    private String name;
    private String version;
    private int port;
    private boolean enableLogging;
    private Date time;

    // List<String> 类型
    private List<String> authors;

    // Map<String, String> 类型
    private Map<String, String> metadata;

    // 嵌套对象类型（Datasource）
    private Datasource datasource;

    // 多级嵌套对象（limits.timeout）
    private Limits limits;

    // 嵌套对象类型（User）
    private User user;

    // 嵌套对象列表类型（UserList）
    private List<User> userList;

    @Data
    public static class Datasource {
        private String url;
        private String username;
        private String password;
    }

    @Data
    public static class Limits {
        private int maxUsers;
        private Timeout timeout;

        @Data
        public static class Timeout {
            private int connect;
            private int read;
        }
    }

    @Data
    public static class User {
        private String name;
        private int age;
        private boolean isMale;
    }

}
